package cdu.javaendwork.Controller.Admin.Goods;

import cdu.javaendwork.model.sqlModel.Goods;
import cdu.javaendwork.service.Impl.Shopping.GoodsServiceImpl;
import cdu.javaendwork.service.Interface.Shopping.GoodsService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/admin/goods_mod")
public class GoodsModController extends HttpServlet {
    GoodsService goodsService = new GoodsServiceImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //处理参数
        String sPage=req.getParameter("page");
        int pageSize=3;
        int pageIndex=(sPage == null || sPage.equals("")) ? 1 : Integer.parseInt(sPage);
        String gid = req.getParameter("goodid");
        int goodsid = Integer.parseInt(gid);
        String st = req.getParameter("status");
        int status = Integer.parseInt(st);
        String goodsname = req.getParameter("goodsname");

        //对状态码做处理
        Goods goods = goodsService.findById(goodsid);
        goodsService.update(goodsid,goods.getName(),goods.getPrice(),status,goods.getPhoto(),goods.getDescription());

        //分情况转发请求 维持原页面原页码
        if(goodsname==null || goodsname == "") req.getRequestDispatcher("goods_list").forward(req,resp);
        else req.getRequestDispatcher("goods_select").forward(req,resp);
    }
}
